package com.wz.rx;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.functions.Consumer;
import io.reactivex.internal.util.AppendOnlyLinkedArrayList;
import io.reactivex.schedulers.Schedulers;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import sun.rmi.runtime.Log;

import java.util.concurrent.TimeUnit;

/**
 * Created by wangzhen1 on 2017/6/29.
 */
public class Interval {

    public static void main(String[] args) {
        Flowable
                .interval(1, TimeUnit.SECONDS)
                .observeOn(Schedulers.newThread())
                .filter((AppendOnlyLinkedArrayList.NonThrowingPredicate<Long>) aLong -> aLong % 2 == 0)
                .subscribe(new Subscriber<Long>() {

                    @Override
                    public void onSubscribe(Subscription s) {
                        System.out.println("onSubscribe--------");
                        s.request(1);
                    }

                    @Override
                    public void onNext(Long aLong) {
                        System.out.println("打印：" + aLong);
                    }

                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {
                        System.out.println("onComplete--------");
                    }
                });

        Flowable.range(1, 1000000000)
                .filter((AppendOnlyLinkedArrayList.NonThrowingPredicate<Integer>) aInteger -> aInteger % 2 == 0)
                .subscribe(integer -> {
                    Thread.sleep(100);
                    System.out.println(integer);
                });

    }

}
